home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-9.10-netbook-remix-PL.iso / casper / filesystem.squashfs / usr / lib / python2.6 / distutils / bcppcompiler.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-11-11  |  8KB  |  331 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''distutils.bcppcompiler
  5.  
  6. Contains BorlandCCompiler, an implementation of the abstract CCompiler class
  7. for the Borland C++ compiler.
  8. '''
  9. __revision__ = '$Id: bcppcompiler.py 61000 2008-02-23 17:40:11Z christian.heimes $'
  10. import os
  11. from distutils.errors import DistutilsExecError, DistutilsPlatformError, CompileError, LibError, LinkError, UnknownFileError
  12. from distutils.ccompiler import CCompiler, gen_preprocess_options, gen_lib_options
  13. from distutils.file_util import write_file
  14. from distutils.dep_util import newer
  15. from distutils import log
  16.  
  17. class BCPPCompiler(CCompiler):
  18.     '''Concrete class that implements an interface to the Borland C/C++
  19.     compiler, as defined by the CCompiler abstract class.
  20.     '''
  21.     compiler_type = 'bcpp'
  22.     executables = { }
  23.     _c_extensions = [
  24.         '.c']
  25.     _cpp_extensions = [
  26.         '.cc',
  27.         '.cpp',
  28.         '.cxx']
  29.     src_extensions = _c_extensions + _cpp_extensions
  30.     obj_extension = '.obj'
  31.     static_lib_extension = '.lib'
  32.     shared_lib_extension = '.dll'
  33.     static_lib_format = shared_lib_format = '%s%s'
  34.     exe_extension = '.exe'
  35.     
  36.     def __init__(self, verbose = 0, dry_run = 0, force = 0):
  37.         CCompiler.__init__(self, verbose, dry_run, force)
  38.         self.cc = 'bcc32.exe'
  39.         self.linker = 'ilink32.exe'
  40.         self.lib = 'tlib.exe'
  41.         self.preprocess_options = None
  42.         self.compile_options = [
  43.             '/tWM',
  44.             '/O2',
  45.             '/q',
  46.             '/g0']
  47.         self.compile_options_debug = [
  48.             '/tWM',
  49.             '/Od',
  50.             '/q',
  51.             '/g0']
  52.         self.ldflags_shared = [
  53.             '/Tpd',
  54.             '/Gn',
  55.             '/q',
  56.             '/x']
  57.         self.ldflags_shared_debug = [
  58.             '/Tpd',
  59.             '/Gn',
  60.             '/q',
  61.             '/x']
  62.         self.ldflags_static = []
  63.         self.ldflags_exe = [
  64.             '/Gn',
  65.             '/q',
  66.             '/x']
  67.         self.ldflags_exe_debug = [
  68.             '/Gn',
  69.             '/q',
  70.             '/x',
  71.             '/r']
  72.  
  73.     
  74.     def compile(self, sources, output_dir = None, macros = None, include_dirs = None, debug = 0, extra_preargs = None, extra_postargs = None, depends = None):
  75.         (macros, objects, extra_postargs, pp_opts, build) = self._setup_compile(output_dir, macros, include_dirs, sources, depends, extra_postargs)
  76.         if not extra_preargs:
  77.             pass
  78.         compile_opts = []
  79.         compile_opts.append('-c')
  80.         if debug:
  81.             compile_opts.extend(self.compile_options_debug)
  82.         else:
  83.             compile_opts.extend(self.compile_options)
  84.         for obj in objects:
  85.             
  86.             try:
  87.                 (src, ext) = build[obj]
  88.             except KeyError:
  89.                 continue
  90.  
  91.             src = os.path.normpath(src)
  92.             obj = os.path.normpath(obj)
  93.             self.mkpath(os.path.dirname(obj))
  94.             if ext == '.res':
  95.                 continue
  96.             
  97.             if ext == '.rc':
  98.                 
  99.                 try:
  100.                     self.spawn([
  101.                         'brcc32',
  102.                         '-fo',
  103.                         obj,
  104.                         src])
  105.                 continue
  106.                 except DistutilsExecError:
  107.                     msg = None
  108.                     raise CompileError, msg
  109.                     continue
  110.                 
  111.  
  112.             
  113.             if ext in self._c_extensions:
  114.                 input_opt = ''
  115.             elif ext in self._cpp_extensions:
  116.                 input_opt = '-P'
  117.             else:
  118.                 input_opt = ''
  119.             output_opt = '-o' + obj
  120.             
  121.             try:
  122.                 self.spawn([
  123.                     self.cc] + compile_opts + pp_opts + [
  124.                     input_opt,
  125.                     output_opt] + extra_postargs + [
  126.                     src])
  127.             continue
  128.             except DistutilsExecError:
  129.                 msg = None
  130.                 raise CompileError, msg
  131.                 continue
  132.             
  133.  
  134.         
  135.         return objects
  136.  
  137.     
  138.     def create_static_lib(self, objects, output_libname, output_dir = None, debug = 0, target_lang = None):
  139.         (objects, output_dir) = self._fix_object_args(objects, output_dir)
  140.         output_filename = self.library_filename(output_libname, output_dir = output_dir)
  141.         if self._need_link(objects, output_filename):
  142.             lib_args = [
  143.                 output_filename,
  144.                 '/u'] + objects
  145.             if debug:
  146.                 pass
  147.             
  148.             
  149.             try:
  150.                 self.spawn([
  151.                     self.lib] + lib_args)
  152.             except DistutilsExecError:
  153.                 msg = None
  154.                 raise LibError, msg
  155.             except:
  156.                 None<EXCEPTION MATCH>DistutilsExecError
  157.             
  158.  
  159.         None<EXCEPTION MATCH>DistutilsExecError
  160.         log.debug('skipping %s (up-to-date)', output_filename)
  161.  
  162.     
  163.     def link(self, target_desc, objects, output_filename, output_dir = None, libraries = None, library_dirs = None, runtime_library_dirs = None, export_symbols = None, debug = 0, extra_preargs = None, extra_postargs = None, build_temp = None, target_lang = None):
  164.         (objects, output_dir) = self._fix_object_args(objects, output_dir)
  165.         (libraries, library_dirs, runtime_library_dirs) = self._fix_lib_args(libraries, library_dirs, runtime_library_dirs)
  166.         if runtime_library_dirs:
  167.             log.warn("I don't know what to do with 'runtime_library_dirs': %s", str(runtime_library_dirs))
  168.         
  169.         if output_dir is not None:
  170.             output_filename = os.path.join(output_dir, output_filename)
  171.         
  172.         if self._need_link(objects, output_filename):
  173.             if target_desc == CCompiler.EXECUTABLE:
  174.                 startup_obj = 'c0w32'
  175.                 if debug:
  176.                     ld_args = self.ldflags_exe_debug[:]
  177.                 else:
  178.                     ld_args = self.ldflags_exe[:]
  179.             else:
  180.                 startup_obj = 'c0d32'
  181.                 if debug:
  182.                     ld_args = self.ldflags_shared_debug[:]
  183.                 else:
  184.                     ld_args = self.ldflags_shared[:]
  185.             if export_symbols is None:
  186.                 def_file = ''
  187.             else:
  188.                 (head, tail) = os.path.split(output_filename)
  189.                 (modname, ext) = os.path.splitext(tail)
  190.                 temp_dir = os.path.dirname(objects[0])
  191.                 def_file = os.path.join(temp_dir, '%s.def' % modname)
  192.                 contents = [
  193.                     'EXPORTS']
  194.                 for sym in []:
  195.                     contents.append('  %s=_%s' % (sym, sym))
  196.                 self.execute(write_file, (def_file, contents), 'writing %s' % def_file)
  197.             objects2 = map(os.path.normpath, objects)
  198.             objects = [
  199.                 startup_obj]
  200.             resources = []
  201.             for file in objects2:
  202.                 (base, ext) = os.path.splitext(os.path.normcase(file))
  203.                 if ext == '.res':
  204.                     resources.append(file)
  205.                     continue
  206.                 objects.append(file)
  207.             
  208.             for l in library_dirs:
  209.                 ld_args.append('/L%s' % os.path.normpath(l))
  210.             
  211.             ld_args.append('/L.')
  212.             ld_args.extend(objects)
  213.             ld_args.extend([
  214.                 ',',
  215.                 output_filename])
  216.             ld_args.append(',,')
  217.             for lib in libraries:
  218.                 libfile = self.find_library_file(library_dirs, lib, debug)
  219.                 if libfile is None:
  220.                     ld_args.append(lib)
  221.                     continue
  222.                 ld_args.append(libfile)
  223.             
  224.             ld_args.append('import32')
  225.             ld_args.append('cw32mt')
  226.             ld_args.extend([
  227.                 ',',
  228.                 def_file])
  229.             ld_args.append(',')
  230.             ld_args.extend(resources)
  231.             if extra_preargs:
  232.                 ld_args[:0] = extra_preargs
  233.             
  234.             if extra_postargs:
  235.                 ld_args.extend(extra_postargs)
  236.             
  237.             self.mkpath(os.path.dirname(output_filename))
  238.             
  239.             try:
  240.                 self.spawn([
  241.                     self.linker] + ld_args)
  242.             except DistutilsExecError:
  243.                 msg = None
  244.                 raise LinkError, msg
  245.             except:
  246.                 None<EXCEPTION MATCH>DistutilsExecError
  247.             
  248.  
  249.         None<EXCEPTION MATCH>DistutilsExecError
  250.         log.debug('skipping %s (up-to-date)', output_filename)
  251.  
  252.     
  253.     def find_library_file(self, dirs, lib, debug = 0):
  254.         if debug:
  255.             dlib = lib + '_d'
  256.             try_names = (dlib + '_bcpp', lib + '_bcpp', dlib, lib)
  257.         else:
  258.             try_names = (lib + '_bcpp', lib)
  259.         for dir in dirs:
  260.             for name in try_names:
  261.                 libfile = os.path.join(dir, self.library_filename(name))
  262.                 if os.path.exists(libfile):
  263.                     return libfile
  264.             
  265.         else:
  266.             return None
  267.         return os.path.exists(libfile)
  268.  
  269.     
  270.     def object_filenames(self, source_filenames, strip_dir = 0, output_dir = ''):
  271.         if output_dir is None:
  272.             output_dir = ''
  273.         
  274.         obj_names = []
  275.         for src_name in source_filenames:
  276.             (base, ext) = os.path.splitext(os.path.normcase(src_name))
  277.             if ext not in self.src_extensions + [
  278.                 '.rc',
  279.                 '.res']:
  280.                 raise UnknownFileError, "unknown file type '%s' (from '%s')" % (ext, src_name)
  281.             ext not in self.src_extensions + [
  282.                 '.rc',
  283.                 '.res']
  284.             if strip_dir:
  285.                 base = os.path.basename(base)
  286.             
  287.             if ext == '.res':
  288.                 obj_names.append(os.path.join(output_dir, base + ext))
  289.                 continue
  290.             if ext == '.rc':
  291.                 obj_names.append(os.path.join(output_dir, base + '.res'))
  292.                 continue
  293.             obj_names.append(os.path.join(output_dir, base + self.obj_extension))
  294.         
  295.         return obj_names
  296.  
  297.     
  298.     def preprocess(self, source, output_file = None, macros = None, include_dirs = None, extra_preargs = None, extra_postargs = None):
  299.         (_, macros, include_dirs) = self._fix_compile_args(None, macros, include_dirs)
  300.         pp_opts = gen_preprocess_options(macros, include_dirs)
  301.         pp_args = [
  302.             'cpp32.exe'] + pp_opts
  303.         if output_file is not None:
  304.             pp_args.append('-o' + output_file)
  305.         
  306.         if extra_preargs:
  307.             pp_args[:0] = extra_preargs
  308.         
  309.         if extra_postargs:
  310.             pp_args.extend(extra_postargs)
  311.         
  312.         pp_args.append(source)
  313.         if self.force and output_file is None or newer(source, output_file):
  314.             if output_file:
  315.                 self.mkpath(os.path.dirname(output_file))
  316.             
  317.             
  318.             try:
  319.                 self.spawn(pp_args)
  320.             except DistutilsExecError:
  321.                 msg = None
  322.                 print msg
  323.                 raise CompileError, msg
  324.             except:
  325.                 None<EXCEPTION MATCH>DistutilsExecError
  326.             
  327.  
  328.         None<EXCEPTION MATCH>DistutilsExecError
  329.  
  330.  
  331.